package com.jt.controller;

import com.jt.pojo.Order;
import com.jt.service.OrderService;
import com.jt.vo.OrderVO;
import com.jt.vo.PageResult;
import com.jt.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.UUID;

@RestController
@CrossOrigin
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    //展示订单列表
    @GetMapping("/getOrderList")
    public SysResult getOrderList(PageResult pageResult){
        pageResult = orderService.getOrderList(pageResult);
        return SysResult.success(pageResult);
    }

    //创建订单
    @PostMapping("/createOrder")
    @Transactional
    public SysResult createOrder(@RequestBody OrderVO orderVO){
        String UUID = java.util.UUID.randomUUID().toString();
        Order order = orderVO.getOrder();
        order.setOrderNum(UUID);
        orderService.createOrder(orderVO);
        return SysResult.success();
    }

    //订单删除
    @DeleteMapping("/deleteOrder")
    @Transactional
    public SysResult deleteOrder(@PathVariable Integer id){
        orderService.deleteOrder(id);
        return SysResult.success();
    }

    //订单修改
    @PutMapping("/updateOrder")
    @Transactional
    public SysResult updateOrder(@RequestBody OrderVO orderVO){
        orderService.updateOrder(orderVO);
        return SysResult.success();
    }

}
